package miku.firstgame.net.pack
{
	import miku.firstgame.constrants.ProtocalConstants;
	import miku.firstgame.model.Room;
	import miku.firstgame.model.User;
	import miku.firstgame.net.ByteArrayEx;

	public class ExitRoomResponsePack extends AbstractReponsePack
	{
		public var result:int;

		public var users:Vector.<User>;
		public var rooms:Vector.<Room>;

		public function ExitRoomResponsePack(data:ByteArrayEx)
		{
			super(data);
			users = new Vector.<User>();
			rooms = new Vector.<Room>();
		}

		override public function get tag():int
		{
			return ProtocalConstants.EXIT_ROOM;
		}

		override public function decode():void
		{
			super.decode();
			data.position = 4;
			result = data.readUnsignedByte();
			if (result == 0)
			{
				var userCount:int = data.readUnsignedInt();
				for (var i:int = 0; i < userCount; i++)
				{
					var user:User = User.parseUser(data);
					users.push(user);
				}

				var roomCount:int = data.readUnsignedInt();
				for (var j:int = 0; j < roomCount; j++)
				{
					var room:Room = Room.parseRoom(data);
					rooms.push(room);
				}
			}
		}
	}
}
